app=$1
img=$2

docker pull $img

echo "正在启动 $app ..."
 
host_ip=$(docker network inspect bridge | grep Gateway | awk '{print $NF}' | sed 's/"//g')

docker kill $app ; docker rm $app

vp=""

if [ "$app" == "mp-admin-api" -o "$app" == "mp-gateway-api" ]; then
   vp=" --privileged=true -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -v /etc/docker:/etc/docker  -v /:/r "
fi

if [ "$app" == "mp-admin-api" ]; then
   vp="$vp -m 2048m "
else
   vp="$vp -m 2048m "
fi

if [ "$app" == "mp-gateway-api" ]; then
   vp=" $vp -p 9898:80 " 
fi


docker run -d  --name $app --net vm \
  $vp -e PROFILE=prod -e APP_NAME=$app \
  --add-host=nacos:172.20.0.1 \
  --add-host=mysql:172.20.0.1 \
  --add-host=mongo:172.20.0.1 \
  --add-host=thc:172.20.0.1 \
  --add-host=redis:172.20.0.1 \
  --add-host=rabbitmq:172.20.0.1 \
  --add-host=es:172.20.0.1 \
  --add-host=minio:172.20.0.1 \
  $img
